package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import Dao.*;
import Entity.Student;

/**
 * Servlet implementation class UserInformationServlet
 */
//@WebServlet("/UserInformationServlet")
public class UserInformationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserInformationServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");//解决乱码
		response.setContentType("text/html;charset=utf-8");//解决乱码
		response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		HttpSession session=request.getSession();
		String status=request.getParameter("status");
		//System.out.print(status);
		out.print(status);
		if(status.equals("student")) {
			//List<String> allStudentsList=new ArrayList<String>();
			int totalRecord=new StudentsInformationDao().queryRecordCount();
			List<Student> allStudentsList=new StudentsInformationDao().showAllStudents();
			session.setAttribute("session_allStudents", allStudentsList);
			//out.print("<div class='body-right'>");
			out.print("<table border='1'>");
			out.print("<tr>");
			out.print("<td>"+"学号"+"</td>");
			out.print("<td>"+"姓名"+"</td>");
			out.print("<td>"+"性别"+"</td>");
			out.print("<td>"+"学院"+"</td>");
			out.print("<td>"+"专业"+"</td>");
			out.print("<td>"+"班级"+"</td>");
			out.print("<td>"+"身份证号"+"</td>");
			out.print("<td>"+"密码"+"</td>");
			out.print("<td>"+"电话"+"</td>");
			out.print("</tr>");						
			//String [][]allStudents=(String[][])session.getAttribute("session_allStudents");
			for(int i=0;i<totalRecord;i++){
				out.print("<tr>");
				out.print("<td>"+allStudentsList.get(i).getStudentNo()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getStudentName()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getSex()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getDept()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getMajor()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getStudentClass()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getStudentId()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getPwd()+"</td>");
				out.print("<td>"+allStudentsList.get(i).getTel()+"</td>");		
				out.print("</tr>");
			}
			
			}
			out.print("</table>");
			//out.print("</div>");	
		out.flush();
		out.close();
		//session.removeAttribute("session_allStudents");
		//response.sendRedirect("administratorPage.jsp");
	}

}
